﻿@model Atomic.Permission.Entities.FormEntity
<script type="text/javascript">
    var jqEditPanel, jqOperateEditPanel;
    $(function () {
        jqEditPanel = $('#editPanel');
        jqOperateEditPanel = $('#operateEditPanel');
        jqEditPanel.dialog({
            title: '新建/编辑项',
            buttons: [
                {
                    text: '保存',
                    handler: function () {
                        $('form', jqEditPanel).submit();
                    }
                }
            ]
        });
        jqOperateEditPanel.dialog({
            title: '新建/编辑专属功能',
            buttons: [
                {
                    text: '保存',
                    handler: function () {
                        $('form', jqOperateEditPanel).submit();
                    }
                }
            ]
        });

        $('#add1').click(function () {
            $('text,textarea', jqEditPanel).val('');
            $('#ID', jqEditPanel).val(0);
            $('#PID', jqEditPanel).val(0);
            $('#PName', jqEditPanel).text('');
            jqEditPanel.dialog('open');
        });
        $('#add2').click(function () {
            var node = $('#list').treegrid('getSelected');
            if (node) {
                $('#ID', jqEditPanel).val(0);
                $('#PID', jqEditPanel).val(node.ID);
                $('#PName', jqEditPanel).text(node.Name);
                jqEditPanel.dialog('open');
            } else {
                $.messager.alert('提示信息', '请选择要新建子节点的项', 'warning');
            }
        });
        $('#add3').click(function () {
            var data = $('#list').treegrid('getSelected');
            if (data) {
                $('#OperatePoint_FunPointID').val(data.ID);
                $('#OperatePoint_FunPointName').val(data.Name);
                jqOperateEditPanel.dialog('open');
            } else {
                $.messager.alert('提示信息', '请选择要新建专属操作点的项', 'warning');
            }
        });

        $('#list').treegrid({
            url: '@Url.Content("~/Permission/FunPointTree")',
            idField: 'ID',
            treeField: 'Key',
            fit: true,
            border: false,
            nowrap: false,
            singleSelect: true,
            toolbar: [
            {
                text: "编辑",
                iconCls: "icon-edit",
                plain: true,
                handler: function () {
                    var data = $('#list').treegrid('getSelected');
                    if (data) {
                        $('#ID', jqEditPanel).val(data.ID);
                        $('#PID', jqEditPanel).val(data.PID);
                        $('#Key', jqEditPanel).val(data.Key);
                        $('#Name', jqEditPanel).val(data.Name);
                        $('#Url', jqEditPanel).val(data.Url);
                        $('#Sort', jqEditPanel).val(data.Sort);
                        $('#Cls', jqEditPanel).val(data.Cls);
                        $('#Enabled', jqEditPanel).attr('checked', data.Enabled);
                        jqEditPanel.dialog('open');
                    } else {
                        $.messager.alert('提示信息', '请选择要编辑的项', 'warning');
                    }
                }
            },
            {
                text: "删除",
                iconCls: "icon-remove",
                plain: true,
                handler: function () {
                    var data = $('#list').treegrid('getSelected');
                    if (null == data) {
                        $.messager.alert('提示信息', '请选择要删除的项', 'warning');
                    } else {
                        $.messager.confirm('提示信息','确定删除选中项？', function (btn) {
                            if (btn) {
                                $.post('@Url.Content("~/Permission/FunPointRemove")',
                                {
                                    id: data.ID
                                },
                                function () {
                                    $('#list').treegrid('remove', data.ID);
                                });
                            }
                        });
                    }
                }
            }],
            frozenColumns: [[
	                { title: '键值', field: 'Key', width: 250 }
				]],
            columns: [[
                    { field: 'Sort', title: '顺序', width: 50 },
                    { field: 'Name', title: '功能名', width: 100 },
                    { field: 'Enabled', title: '是否启用', width: 60,
                        formatter: function (v) {
                            if (v) {
                                return '是';
                            } else {
                                return '<span style="color:#f00;">否<span>';
                            }
                        }
                    },
                    { field: 'Url', title: '地址/路径', width: 250 },
                    { field: 'Cls', title: '样式', width: 150 }
                ]]
        });
        //多级菜单
        $('#funPointIndexToolbar').prependTo('#funPointIndex .datagrid-toolbar');
    });
    function onSuccess(data) {
        if (data.Success) {
            jqEditPanel.dialog('close');
            $('input:text,textarea', jqEditPanel).val('');
            $('#list').treegrid('reload', 0);
        }
    }
    function onOperateSuccess(data) {
        if (data.Success) {
            $.messager.alert('提示信息', '专属操作点创建成功,你可以到操作点管理页面修改或删除', 'info');
            jqOperateEditPanel.dialog('close');
            $('input:text,textarea', jqOperateEditPanel).val('');
        }
    }
</script>
<div id="funPointIndex" class="easyui-panel" fit="true" border="false">
    <div id="list">
    </div>
    <div id="funPointIndexToolbar" style="float: left">
        <a href="javascript:void(0)" id="mb" class="easyui-splitbutton" menu="#mm" iconcls="icon-add">
            新建</a>
        <div id="mm" style="width: 100px;">
            <div id="add1" iconcls="icon-folder">
                根节点</div>
            <div id="add2" iconcls="icon-file">
                子节点</div>
            <div class="menu-sep">
            </div>
            <div id="add3" iconcls="icon-function">
                专属操作点</div>
        </div>
    </div>
</div>
<div id="editPanel">
    @using (Ajax.BeginForm("FunPointAddOrUpdate", new AjaxOptions
    {
        HttpMethod = "Post",
        OnSuccess = "onSuccess"
    }))
    {
        @Html.HiddenFor(m => m.ID)
        @Html.HiddenFor(m => m.PID)
        <table class="form-tab top" style="width: 500px">
            <tr>
                <td class="left">
                    @Html.LabelFor(m => m.Key)：
                </td>
                <td>
                    @Html.TextBoxFor(m => m.Key, new { @class = "text" })
                    @Html.ValidationMessageFor(m => m.Key)
                </td>
            </tr>
            <tr>
                <td class="left">
                    @Html.LabelFor(m => m.Name)：
                </td>
                <td>
                    @Html.TextBoxFor(m => m.Name, new { @class = "text", @maxlength = "20" })
                    @Html.ValidationMessageFor(m => m.Name)
                </td>
            </tr>
            <tr>
                <td class="left">
                    父功能名：
                </td>
                <td>
                    <span id="PName"></span>
                </td>
            </tr>
            <tr>
                <td class="left">
                    @Html.LabelFor(m => m.Url)：
                </td>
                <td>
                    @Html.TextBoxFor(m => m.Url, new { @class = "text", @maxlength = "255", @style = "width:90%;" })
                    @Html.ValidationMessageFor(m => m.Url)
                </td>
            </tr>
            <tr>
                <td class="left">
                    @Html.LabelFor(m => m.Sort)：
                </td>
                <td>
                    @Html.TextBoxFor(m => m.Sort, new { @class = "text easyui-numberbox" })
                    @Html.ValidationMessageFor(m => m.Sort)
                </td>
            </tr>
            <tr>
                <td class="left">
                    @Html.LabelFor(m => m.Cls)：
                </td>
                <td>
                    @Html.TextBoxFor(m => m.Cls, new { @class = "text" })
                    @Html.ValidationMessageFor(m => m.Cls)
                </td>
            </tr>
            <tr>
                <td class="left">
                    @Html.LabelFor(m => m.Enabled)：
                </td>
                <td>
                    @Html.CheckBoxFor(m => m.Enabled, new { @checked = true })
                </td>
            </tr>
        </table>
    }
</div>
<div id="operateEditPanel">
    <div style="width:450px;" class="easyui-panel" border="false" href="@Url.Content("~/Permission/OperatePointAddOrUpdateControl")">
    </div>
</div>
